/*
 * Interface gráfica para lançamento de faltas para um aluno de uma turma.
 */
package amanda_gabriel_isabella_lucivania_monica.View;

import amanda_gabriel_isabella_lucivania_monica.Model.Dao.DaoBaseImpl;
import amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Aluno;
import amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Faltas;
import amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Turma;

/**
 * Interface gráfica de lançar faltar
 *
 * @author monica
 * @param daoBaseImpl
 */
public class LancarFaltasIG extends javax.swing.JFrame {

    private DaoBaseImpl daoBaseImpl;

    /**
     * Cria um novo form LancarFaltasIG
     *
     * @param DaoBase
     */
    public LancarFaltasIG(DaoBaseImpl daobaseImpl) {
        initComponents();
        this.daoBaseImpl = daobaseImpl;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDSucesso = new javax.swing.JDialog();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jBuSim = new javax.swing.JButton();
        jBNaoL = new javax.swing.JButton();
        jDCamposVazios = new javax.swing.JDialog();
        jLabel3 = new javax.swing.JLabel();
        jBOK1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLNome = new javax.swing.JLabel();
        jLAluno = new javax.swing.JLabel();
        jLFaltas = new javax.swing.JLabel();
        jTFaltas = new javax.swing.JTextField();
        jCTurma = new javax.swing.JComboBox();
        jCBAluno = new javax.swing.JComboBox();
        jBSalvar = new javax.swing.JButton();
        jBCancelar = new javax.swing.JButton();

        jDSucesso.setTitle("Confirmação");
        jDSucesso.setMinimumSize(new java.awt.Dimension(400, 175));

        jLabel1.setText("Faltas lançadas com sucesso!");

        jLabel2.setText("Deseja lançar efetuar outro lançamento?");

        jBuSim.setText("Sim");
        jBuSim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBuSimActionPerformed(evt);
            }
        });

        jBNaoL.setText("Não");
        jBNaoL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNaoLActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDSucessoLayout = new javax.swing.GroupLayout(jDSucesso.getContentPane());
        jDSucesso.getContentPane().setLayout(jDSucessoLayout);
        jDSucessoLayout.setHorizontalGroup(
            jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDSucessoLayout.createSequentialGroup()
                .addGroup(jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jDSucessoLayout.createSequentialGroup()
                        .addGap(82, 82, 82)
                        .addComponent(jLabel1))
                    .addGroup(jDSucessoLayout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addComponent(jLabel2))
                    .addGroup(jDSucessoLayout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addComponent(jBuSim)
                        .addGap(38, 38, 38)
                        .addComponent(jBNaoL, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(39, Short.MAX_VALUE))
        );

        jDSucessoLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jBNaoL, jBuSim});

        jDSucessoLayout.setVerticalGroup(
            jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDSucessoLayout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addGroup(jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBuSim)
                    .addComponent(jBNaoL))
                .addContainerGap(42, Short.MAX_VALUE))
        );

        jDCamposVazios.setMinimumSize(new java.awt.Dimension(400, 175));

        jLabel3.setText("Todos os campos devem ser preenchidos!");

        jBOK1.setText("OK");
        jBOK1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBOK1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDCamposVaziosLayout = new javax.swing.GroupLayout(jDCamposVazios.getContentPane());
        jDCamposVazios.getContentPane().setLayout(jDCamposVaziosLayout);
        jDCamposVaziosLayout.setHorizontalGroup(
            jDCamposVaziosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDCamposVaziosLayout.createSequentialGroup()
                .addGroup(jDCamposVaziosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jDCamposVaziosLayout.createSequentialGroup()
                        .addGap(69, 69, 69)
                        .addComponent(jLabel3))
                    .addGroup(jDCamposVaziosLayout.createSequentialGroup()
                        .addGap(148, 148, 148)
                        .addComponent(jBOK1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(56, Short.MAX_VALUE))
        );
        jDCamposVaziosLayout.setVerticalGroup(
            jDCamposVaziosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDCamposVaziosLayout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addComponent(jBOK1)
                .addContainerGap(36, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Lançar faltas");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Informe os dados abaixo:"));

        jLNome.setText("Turma:");

        jLAluno.setText("Aluno:");

        jLFaltas.setText("Faltas:");

        jCTurma.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jCBAluno.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLNome)
                    .addComponent(jLFaltas)
                    .addComponent(jLAluno))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTFaltas, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCBAluno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCTurma, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(75, Short.MAX_VALUE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jCBAluno, jCTurma});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLNome)
                    .addComponent(jCTurma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLAluno)
                    .addComponent(jCBAluno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTFaltas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLFaltas))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jCBAluno, jCTurma});

        jBSalvar.setText("Salvar");
        jBSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSalvarActionPerformed(evt);
            }
        });

        jBCancelar.setText("Cancelar");
        jBCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jBSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jBCancelar)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jBCancelar, jBSalvar});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBSalvar)
                    .addComponent(jBCancelar))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jBCancelar, jBSalvar});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBuSimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBuSimActionPerformed
        jDSucesso.dispose();
        setVisible(true);
    }//GEN-LAST:event_jBuSimActionPerformed

    private void jBNaoLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBNaoLActionPerformed
        jDSucesso.dispose();
        setVisible(false);
    }//GEN-LAST:event_jBNaoLActionPerformed

    private void jBCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarActionPerformed
        setVisible(false);
    }//GEN-LAST:event_jBCancelarActionPerformed

    private void jBSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSalvarActionPerformed
        Turma turma = (Turma) jCTurma.getSelectedItem();
        Aluno aluno = (Aluno) jCBAluno.getSelectedItem();
        int numeroFaltas = Integer.parseInt(jTFaltas.getText());

        int indexTurma = jCTurma.getSelectedIndex();
        int indexAluno = jCBAluno.getSelectedIndex();

        if ((indexAluno == -1) || (indexTurma == -1) || (jTFaltas.getText() == "")) {
            jDCamposVazios.setVisible(true);
            setVisible(false);
        } else {
            Faltas faltas = new Faltas(numeroFaltas, aluno, turma);
            daoBaseImpl.create(faltas);

            jTFaltas.setText("");
            jDSucesso.setVisible(true);
        }
    }//GEN-LAST:event_jBSalvarActionPerformed

    private void jBOK1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBOK1ActionPerformed
        setVisible(true);
        jDCamposVazios.dispose();
    }//GEN-LAST:event_jBOK1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBCancelar;
    private javax.swing.JButton jBNaoL;
    private javax.swing.JButton jBOK;
    private javax.swing.JButton jBOK1;
    private javax.swing.JButton jBSalvar;
    private javax.swing.JButton jBuSim;
    private javax.swing.JComboBox jCBAluno;
    private javax.swing.JComboBox jCTurma;
    private javax.swing.JDialog jDCamposVazios;
    private javax.swing.JDialog jDSucesso;
    private javax.swing.JLabel jLAluno;
    private javax.swing.JLabel jLFaltas;
    private javax.swing.JLabel jLNome;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTFaltas;
    // End of variables declaration//GEN-END:variables
}
